package com.yuyou.fn.crm.mapper;

import com.github.wens.mybatisplus.mapper.AutoMapper;
import com.yuyou.fn.crm.entity.CustomerResource;
import com.yuyou.fn.crm.vo.AggregationOfStudentReg;
import com.yuyou.fn.crm.vo.CustomerResourceImportNumVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 * CustomerResource 表数据库控制层接口
 *
 */
public interface CustomerResourceMapper extends AutoMapper<CustomerResource,Long> {


    @Select("<script>" +
            "<![CDATA[" +
            "select min(sr.create_time) as firstRegTime, ccr.customer_resource_id customerResourceId, ccr.student_id studentId , count(*) regAmount ,sum(sr.pay_amount - sr.refund_amount ) totalAmount from crm_customer_resource ccr left join student_reg sr on ccr.student_id =  sr.student_id and ccr.create_time < sr.create_time " +
            "where sr.reg_status = 0  and ccr.customer_resource_id in " +
            "]]>" +
            "<foreach item='item' index='index' collection='customerResourceIds' open='(' separator=',' close=')'>\n" +
            "#{item}" +
            "</foreach>" +
            "group by ccr.customer_resource_id , ccr.student_id" +
            "</script>")
    @ResultType(AggregationOfStudentReg.class)
    List<AggregationOfStudentReg> statStudentReg(@Param("customerResourceIds") List<Long> customerResourceIds);


    List<CustomerResourceImportNumVo> findCustomerResourceImportNum(@Param("studentNames") List<String> studentNames,@Param("phoneNos") List<String> phoneNos,@Param("projectNames")List<String> projectNames);
}